package com.example.main;

import android.Manifest;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.common.constant.RoutePath;
import com.example.common.net.ApiService;
import com.google.android.material.tabs.TabLayout;
import com.tbruyelle.rxpermissions2.RxPermissions;

import javax.inject.Inject;

import dagger.hilt.android.AndroidEntryPoint;
import io.reactivex.functions.Consumer;

@Route(path = RoutePath.MAIN_ACTIVITY)
@AndroidEntryPoint
public class MainActivity extends AppCompatActivity {

    @Inject
    ApiService apiService;

    @Inject
    RxPermissions rxPermissions;

    ViewPager viewPager;
    TabLayout tabLayout;


    @RequiresApi(api = Build.VERSION_CODES.DONUT)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        viewPager = findViewById(R.id.view_pager);
        tabLayout = findViewById(R.id.tab_layout);

        // 请求权限 使用RxPermissions的原因是：可使用RxJava
        rxPermissions.request(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .subscribe(new Consumer<Boolean>() {
                    @Override
                    public void accept(Boolean aBoolean) throws Exception {
                        if (aBoolean) {
                            // 获取权限成功
                        } else {
                            // 权限获取失败
                        }
                    }
                });


        initViewPager();

//        StatusBarUtil.setTranslucentForImageView(this, 0, tabLayout);

//        // 测试一下网络请求
//        RequestModel.request(apiService.test(), this, new ICallback<String>() {
//
//            @SuppressLint("LongLogTag")
//            @Override
//            public void onSuccess(String data) {
//                Log.i("TAG_Hermit", "onSuccess: data=" + data);
//            }
//
//            @Override
//            public void onFailure(ApiException e) {
//
//            }
//        });
    }

    private void initViewPager() {

    }
}